<template>
  <div class="login">
    <div class="login-con">
      <Card icon="log-in" title="欢迎登录" :bordered="false">
        <div class="form-con">
          <Form ref="loginForm" :model="form" :rules="rules">
            <FormItem prop="userName">
              <Input v-model="form.userName" placeholder="请输入用户名">
                <span slot="prepend">
                  <Icon :size="16" type="ios-person"></Icon>
                </span>
            </Input>
            </FormItem>
            <FormItem prop="password">
              <Input type="password" v-model="form.password" placeholder="请输入密码">
                <span slot="prepend">
                  <Icon :size="14" type="md-lock"></Icon>
                </span>
              </Input>
            </FormItem>
            <FormItem>
              <Button  type="primary" @click="loginSubmit('loginForm')" long>登录</Button>
            </FormItem>
          </Form>
          <p class="login-tip">输入任意用户名和密码即可</p>
        </div>
      </Card>
    </div>
  </div>
</template>

<script>
// import {checkUser} from '@/api/user'
export default {
  data () {
    return {
      form: {
        userName: 'super_admin',
        password: ''
      },
      rules: {
        userName: [
          { required: true, message: '账号不能为空', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '密码不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    // 登录验证(validate是表单验证方法)
    loginSubmit (formName) {
      this.$refs[formName].validate(valide => {
        if (valide) {
          // checkUser(this.form).then(res => {
          //  if (res.data.code == 200) {
          //     // 成功调转首页,将token保存到localstorage
          //     localStorage.setItem('mytoken', res.data.token)
          //     this.$router.push({name: 'Home'})
          //  } else {
          //    // 失败展示信息
          //    this.$Message.error(res.data.message)
          //  }
          //   console.log(res)
          // })
          this.$router.push({name: 'Home'})
          console.log('校验通过')
        } else {
          this.$Message.error('错误提示')
          console.log('校验不通过')
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
  @import './login.less';
</style>
